import Inject, { ServiceProvider } from "@entity-access/entity-access/dist/di/di.js"; import { Route } from "@entity-access/server-pages/dist/core/Route.js"; import ScopeVars from "../../../common/ScopeVars.js"; import ChannelPageService from "../../../server/services/channels/ChannelPageService.js"; import SSRService from "../../../server/services/ssr/SSRService.js"; import { globalEnv } from "../../../common/globalEnv.js"; import WebSiteContentService from "../../../server/services/files/WebSiteContentService.js"; import { HttpProxyPage } from "../../../server/services/http/HttpProxyService.js"; const socialMail = JSON.stringify({ path: globalEnv.path, name: globalEnv.name, cdn: globalEnv.cdn, links: globalEnv.links, dnsEnabled: globalEnv.dns?.enabled }); export default class BlogPage extends HttpProxyPage { @Inject websiteService: WebSiteContentService; @Inject channelPageService: ChannelPageService; @Route channel: string; async run() { ScopeVars.fromScope(this).fromWebSite = true; // console.log(this.route); // const { channel, slug } = this; // console.log({ channel, slug }); // we will check for bot if ( this.request.query.ssr === "true" || /bot/i.test(this.request.headers["user-agent"])) { if (this.request.query.ssr !== "disable") { const url = this.request.URL; url.searchParams.delete("ssr"); url.searchParams.set("ssr", "disable"); const ssr = ServiceProvider.resolve(this, SSRService); const tf = await ssr.generate(url.toString()); const body = await tf.readAsText(); return this.content({ body, contentType: "text/html" }); } } // lets check slug... const host = this.request.host; const site = await this.websiteService.getCurrentSnapshotFolder(host); if(!site) { return this.notFound(); } const appFile = await this.websiteService.getNamedPageContent(host, ["blog.html", "channel.html"]); if (!appFile) { const prefix = site.remoteUrl; if (prefix) { return this.proxy({ prefix }); } return this.notFound(); } let body = await appFile.readAsText(); this.cacheControl = "public, max-age=900, immutable"; body = body.replace(/\
]*\>/, (s, v) => { return s + ``; }); return this.content({ body, contentType: "text/html" }); } }